﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Xml;
using System.Windows.Markup;
using System.IO;

namespace App7._15
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            LoadContent("Horizontal.xaml");
        }

        void LoadContent(string fileName)
        {
            XmlReader xmlReader = XmlReader.Create(fileName);
            StackPanel stackPanel = XamlReader.Load(xmlReader) as StackPanel;

            Button verticalButton = stackPanel.FindName("vertical") as Button;
            verticalButton.Click += VerticalClick;
            Button horizontalButton = stackPanel.FindName("horizontal") as Button;
            horizontalButton.Click += HorizontalClick;

            Content = stackPanel;
        }

        public void VerticalClick(object sender, RoutedEventArgs args)
        {
            LoadContent("Horizontal.xaml");
        }

        public void HorizontalClick(object sender, RoutedEventArgs args)
        {
            LoadContent("Vertical.xaml");
        }
    }
}
